$(function () {
    initEvent();
});

function initEvent() {
    $("#authenticateUploadBtn").off('click').on('click', function () {
        submitMsg();
    });
}

function takeVideo(obj){
    var files = obj.files;
    if (files && files.length > 0) {  
        var file = files[0];
        if (!/video\/\w+/.test(file.type)) {
            falert("请上传正确的视频文件");
            return false;
        }
        if (file.size > 15 * 1024 * 1024) {
            falert('视频大小不能超过15M，请重新拍摄');
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.addEventListener('loadend', function() {
            $('#videoshow').html('<video height="300" controls="controls" autoplay="autoplay"><source src="'+reader.result+'"/></video>');
            $('#videoType').val(file.type.split('/')[1]);
            $('#videoData').val(reader.result.replace('data:'+file.type+';base64,', ''));
            $("#authenticateUploadBtn").css("display","block");
        })      
    } else {
        falert('请上传视频文件');
    }
}

function submitMsg(){
    var datas = {
        interface:'users@videoform',
        ext:$('#videoType').val(),
        content:$('#videoData').val(),
        motions:$("input[name='videoType']:checked").val()
    };
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                location.href = data.result.jumpUrl;
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
}
